
def main():
    my_list = []
    while True:
        s = input('Enter next name: ')
        if len(s) == 0:
            break
        my_list.append(s)
    my_list.sort()   #对元素进行排序
    print('Here is the sorted list:')
    for a_word in my_list:
        print(a_word,end=' ')

main()


def ignore_case(s):
    return s.casefold()   # casefold() 方法将大写字母全部转化为小写

a_list = ['john','paul','George','brain','Ringo']
b_list = a_list[:]
a_list.sort()
b_list.sort(key=ignore_case)  # ignore_case为上面定义的函数

print(a_list)  # ['George', 'Ringo', 'brain', 'john', 'paul'] 大写字母均小于小写字母，所以排在前面
print(b_list)  # ['brain', 'George', 'john', 'paul', 'Ringo']  用了casefold()方法 不区分大小写的排序

my_list = ['Brain','John','Paul','George','Ringo']
my_list.sort(reverse=True)
for a_word in my_list:
    print(a_word,end=' ')

